﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Vit.Web.Providers.Data;

namespace Vit.DynamicFormModule.Areas.Form.DataProviders
{
    public class InputValueDataProvider : DbContextDataProvider<DynamicFormDb, Models.InputValue>
    {
        protected override IQueryable<Models.InputValue> OrderByDefault(IQueryable<Models.InputValue> query)
        {
            return query.OrderBy(o => o.InputID).ThenBy(o => o.FieldName);
        }

        public override object[] GetKeys(Models.InputValue obj)
        {
            return new object[] { obj.InputID, obj.FieldName };
        }

        public override Models.InputValue GetByKeys(params object[] ids)
        {
            if (ids == null || ids.Length != 2)
                return null;
            string key1 = ids[0].ToString();
            string key2 = ids[1].ToString();
            return db.InputValues.FirstOrDefault(o => o.InputID == key1 && o.FieldName == key2);
        }
    }
}